#ifndef _MESSAGES_H_
#define _MESSAGES_H_

// message ids
typedef enum {
  MessageId_MoveForward,
  MessageId_MoveBackward,
  MessageId_TurnLeft,
  MessageId_TurnRight,
  MessageID_TurretLeft,
  MessageID_TurretRight,
  MessageID_Update
} MessageIdEnum;

// each client has two tank tables: one static, one dynamic.
// tables have same fixed size during the game and one-to-one
// correspondence between elements (array index is the primary key)
// the static table contains tank size, player name etc. (things that don't
// change during a game)
// the dynamic table contains tank state (dead or alive), tank position etc.
// (things that change during the game)

// message definitions
// all messages except MessageID_Update have only msg id (1 byte)
// MessageID_Update message has:
// - msg id (1 byte)
// - tank count (1 byte, the number of tank records in the message)
// (here begins first record)
// - tank index (1 byte, the index in the tank tables)
// - tank health (1 byte, percent of max health, 0 means dead)
// - tank speed (1 byte)
// - x coordinate of tank center (2 bytes)
// - y coordinate of tank center (2 bytes)
// - hull angle in degrees (1 byte, unit is 2 degrees) (
// - turret angle in degrees (1 byte, unit is 2 degrees)

struct ReadBuffer
{
  ReadBuffer(void * buffer) : buffer_ (buffer) {}
  
  unsigned char readByte ()
  {
    return *buffer_++;
  }
  
  unsigned short readWord ()
  {
    unsigned short w = *(unsigned short*)buffer_;
	buffer_ += 2;
	return w;
  }
  
  unsigned char * buffer_;
};

#endif
